import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import './assets/css/global.css'
import 'element-ui/lib/theme-chalk/index.css'
import axios from 'axios'
import TreeTable from 'vue-table-with-tree-grid'
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'
//富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

Vue.use(VueQuillEditor)
//配置axios根路径
axios.defaults.baseURL = 'http://localhost:8888/api/private/v1/'

Vue.prototype.$http = axios
//axios请求拦截器
axios.interceptors.request.use(config => {
  //展示进度条
  Nprogress.start()
  //在请求头中设置 Authorazation
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})
//response中关闭进度条
axios.interceptors.response.use(config => {
  Nprogress.done()
  return config;
})
//全局事件过滤器
Vue.filter('dataFormat', function(originVal) {
  const date = new Date(originVal)
  const y = date.getFullYear()
  //用0填充
  const m = (date.getMonth() + 1 + '').padStart(2,'0')
  const d = (date.getDay()+ '').padStart(2,'0')

  const hh = (date.getHours()+ '').padStart(2,'0')
  const mm = (date.getMinutes()+ '').padStart(2,'0')
  const ss = (date.getSeconds()+ '').padStart(2,'0')

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})
Vue.config.productionTip = false
Vue.component('tree-table', TreeTable)
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')